package com.jcp.baselibrary.dialog;

import android.app.Activity;
import android.app.DialogFragment;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;

import com.jcp.baselibrary.R;


/**
 * 通用的对话框
 * Created by haibin
 * on 2016/11/2.
 */
@SuppressWarnings("all")
public final class DialogHelper {

    /***
     * 获取一个耗时等待对话框
     * @param context
     * @return
     */
    public static ProgressDialog getProgressWaitDialog(Activity activyt) {
        ProgressDialog waitDialog = new ProgressDialog(activyt);
        waitDialog.setCanceledOnTouchOutside(false);
        waitDialog.setCancelable(false);
        return waitDialog;
    }

    /***
     * 获取一个耗时等待对话框
     * @param context
     * @return
     */
    public static LoadingDialog getCustomWaitDialog(Activity activyt) {
        LoadingDialog waitDialog = LoadingDialog.newInstance();
        return waitDialog;
    }

    public static AlertDialog.Builder getDialog(Activity activyt) {
        return new AlertDialog.Builder(activyt);
    }

    public static AlertDialog.Builder getOkDialog(Activity activyt,
                                                  String msgString) {
        return getOkDialog(activyt, null, msgString);
    }

    public static AlertDialog.Builder getOkDialog(Activity activyt,
                                                  String titleString,
                                                  String msgString) {
        return getOkDialog(activyt, titleString, msgString, null);
    }

    public static AlertDialog.Builder getOkDialog(Activity activyt,
                                                  String titleString,
                                                  String msgString,
                                                  DialogInterface.OnClickListener positiveListener) {
        return getOkDialog(activyt, titleString, msgString, true, positiveListener);
    }

    public static AlertDialog.Builder getOkDialog(Activity activyt,
                                                  String titleString,
                                                  String msgString,
                                                  boolean cancelable,
                                                  DialogInterface.OnClickListener positiveListener) {
        return getOkDialog(activyt, titleString, msgString, cancelable, null, positiveListener);
    }

    /**
     * 一个按钮的dialog
     */
    public static AlertDialog.Builder getOkDialog(Activity activyt,
                                                  String titleString,
                                                  String msgString,
                                                  boolean cancelable,
                                                  String btnString,
                                                  DialogInterface.OnClickListener positiveListener) {
        AlertDialog.Builder dialog = getDialog(activyt);
        if (!TextUtils.isEmpty(titleString)) {
            dialog.setTitle(titleString);
        }
        if (!TextUtils.isEmpty(msgString)) {
            dialog.setMessage(msgString);
        }
        dialog.setCancelable(cancelable);
        dialog.setPositiveButton(TextUtils.isEmpty(btnString) ? "确定" : btnString, positiveListener);
        return dialog;
    }

    public static AlertDialog.Builder getOkCancelDialog(Activity activyt,
                                                        String message) {
        return getOkCancelDialog(activyt, "", message);
    }

    public static AlertDialog.Builder getOkCancelDialog(Activity activyt,
                                                        String title,
                                                        String message) {
        return getOkCancelDialog(activyt, title, message, null);
    }

    public static AlertDialog.Builder getOkCancelDialog(Activity activyt,
                                                        String title,
                                                        String message,
                                                        DialogInterface.OnClickListener positiveListener) {
        return getOkCancelDialog(activyt, title, message, null, positiveListener);
    }

    public static AlertDialog.Builder getOkCancelDialog(Activity activyt,
                                                        String title,
                                                        String message,
                                                        DialogInterface.OnClickListener cancelListener,
                                                        DialogInterface.OnClickListener positiveListener) {
        return getOkCancelDialog(activyt, title, message, true, cancelListener, positiveListener);
    }

    public static AlertDialog.Builder getOkCancelDialog(Activity activyt,
                                                        String title,
                                                        String message,
                                                        boolean cancelable,
                                                        DialogInterface.OnClickListener cancelListener,
                                                        DialogInterface.OnClickListener positiveListener) {
        return getOkCancelDialog(activyt, title, message, null, null, cancelable, cancelListener, positiveListener);
    }

    /**
     * 两个按钮的dialog
     */
    public static AlertDialog.Builder getOkCancelDialog(Activity activyt,
                                                        String title,
                                                        String message,
                                                        String cancelStr,
                                                        String okStr,
                                                        boolean cancelable,
                                                        DialogInterface.OnClickListener cancelListener,
                                                        DialogInterface.OnClickListener positiveListener) {
        AlertDialog.Builder dialog = getOkDialog(activyt, title, message, cancelable, okStr, positiveListener);
        dialog.setNegativeButton(TextUtils.isEmpty(cancelStr) ? "取消" : cancelStr, cancelListener);
        return dialog;
    }
}
